package com.metel.mservice.common.bean;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("countries")
public class Countries {
	
	public static final String ISO2_Argentine ="AR";
	public static final String ISO2_UnitedKingdom ="GB";
	public static final String ISO2_SouthKorea ="KR";
	
	@XStreamImplicit
	private List<Country> countries;

	private HashMap<String, Country> iso2Map;
	private HashMap<String, Country> iso3Map;

	public List<Country> getCountries() {
		return countries;
	}

	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}
	
	public void createMap() {
		this.iso2Map = new HashMap<String, Country>();
		this.iso3Map = new HashMap<String, Country>();
		Iterator<Country> itr = countries.iterator();
		Country country;
		while (itr.hasNext()) {
			country = itr.next();
			this.iso2Map.put(country.getIso2(), country);
			this.iso3Map.put(country.getIso3(), country);
		}
	}
	
	public Country getCountryByIso2(String iso2) {
		return this.iso2Map.get(iso2);
	}
	
	public Country getCountryByIso3(String iso3) {
		return this.iso3Map.get(iso3);
	}
	
}
